package main.java.com.web;

import main.java.com.config.PageInfo;
import main.java.com.entity.Category;
import main.java.com.service.CategoryTwoService;
import main.java.com.service.impl.CategoryTwoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/selectcategory")
//展示数据
public class SelectServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置编码格式
        resp.setContentType("text/html;charset=utf-8");
        CategoryTwoService categoryService = new CategoryTwoServiceImpl();
        String pageNoStr = req.getParameter("pageNo");
        int pageNum = 1;
        int pageSize = 5;
        if(pageNoStr != null && !"".equals(pageNoStr)){
            pageNum = Integer.parseInt(pageNoStr);
        }
        PageInfo<Category> list = categoryService.showInfo(pageNum,pageSize);
        req.getSession().setAttribute("list",list);
        req.getRequestDispatcher("/backend/category.jsp").forward(req,resp);
    }
}
